package com.ynu.springbootappdemo.service;

import com.ynu.springbootappdemo.common.service.LogicService;
import com.ynu.springbootappdemo.dao.ICityDao;
import com.ynu.springbootappdemo.model.entity.City;
import com.ynu.springbootappdemo.model.vo.CityVo;
import com.ynu.springbootappdemo.model.vo.FoodVo;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CityService extends LogicService<ICityDao, City,Long> {
    public CityService(@Autowired ICityDao dao) {
        super(dao);
    }

    @Resource
    private ModelMapper modelMapper;

    public List<CityVo> getAllCity(){
        return dao.findAll().stream().map(
                city -> modelMapper.map(city, CityVo.class)).collect(Collectors.toList());
    }

    public CityVo save(City city){
        return modelMapper.map(dao.save(city), CityVo.class);
    }

}
